<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * Class RunGameSeason
 *
 * @package App
 * @mixin \Eloquent
 */
class RunGameSeason extends Model
{
    public $timestamps = false;
    protected $table = "run_game_season";

    const PRICE_NO = 0;
    const PRICE_YES = 1;

    /**
     * 当前赛季ID
     * @return mixed
     */
    static function ThisSeason()
    {
        $time = time();
        return RunGameSeason::where('start_at', '<=', $time)->where('end_at', '>=', $time)->value('id');
    }

    /**
     * @param $request
     * @return array
     */
    static function SeasonAdd($request)
    {
        $season = new RunGameSeason();
        $season->title = $request->title;
        $season->start_at = strtotime($request->start);
        $season->end_at = strtotime($request->end);
        $season->created_at = time();
        if (!$season->save()) {
            return ['status' => 2, 'message' => '失败'];
        }
        return ['status' => 1, 'message' => '成功'];
    }

    /**
     * @param $runGameSeason
     * @param $request
     * @return array
     */
    static function SeasonModify($runGameSeason, $request)
    {
        $runGameSeason->title = $request->title;
        $runGameSeason->start_at = strtotime($request->start);
        $runGameSeason->end_at = strtotime($request->end);
        $runGameSeason->created_at = time();
        if (!$runGameSeason->save()) {
            return ['status' => 2, 'message' => '失败'];
        }
        return ['status' => 1, 'message' => '成功'];
    }
}
